﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class 色彩渐变 : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
    public Color 起始;
    public Color 结束;
    public Color 鼠标颜色;
    public Image 改变对象;
    public float 速度;

    private float 进度 = 0;
    void Start()
    {
        
    }
    bool 反向;
    bool 鼠标;

    public void OnPointerEnter(PointerEventData eventData)
    {
        改变对象.color = 鼠标颜色;
        鼠标 = true;
    }
    public void OnPointerExit(PointerEventData eventData)
    {
        鼠标 = false;
    }

    void Update()
    {

        if (进度 >= 1)
            反向 = true;
        if (进度 <= 0)
            反向 = false;
        if (反向)
            进度 -= 速度;
        else
            进度 += 速度;
        if(!鼠标)
            改变对象.color = Color.Lerp(起始, 结束, 进度);
    }
}
